<%@ page language="java" import="java.util.*"  pageEncoding="UTF-8"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>行政管理--用车管理</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" href="css/chenwenjing/chenwj.css" type="text/css"></link>
	 <link rel="stylesheet" href="easyui/themes/icon.css" type="text/css"></link>
	 <link rel="stylesheet" href="easyui/themes/default/easyui.css" type="text/css"></link>
	 <script type="text/javascript" src="easyui/jquery-1.8.3.js"></script>
	 <script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>
     <script type="text/javascript">
     	$(function(){
	  		$("#dg").datagrid({	  		
	  			url:"car/findAll.do",
	  			striped:true,	  			
	  			rownumbers:true,
	  			pagination:true,
	  			pageList:[10,20,50],
	  			columns:[[{
	  				title:"车牌号",
	  				field:"carno",
	  				width:160,
	  				align:"center",
	  			},{
	  				title:"车型",
	  				field:"cartype",
	  				width:230,
	  				align:"center"
	  			},{
	  				title:"编号",
	  				field:"carid",
	  				width:150,
	  				align:"center"
	  			},{
	  				title:"操作",
	  				field:"id",
	  				width:200,
	  				align:"center",
	  				formatter:function (value,row,index){
						return "<a onclick='update("+row.id+")' href='javascript:void(0)'>修改</a>&nbsp;&nbsp;<a onclick='del("+row.id+")' href='javascript:void(0)'>删除</a>";
					}	  				
	  			}]],
	  			toolbar:[{text:"新增",iconCls:"icon-add",handler:function(){
	  				add();
	  			}}]	
	  		});
	  		
	  		$("#dlg").dialog({
		    title: "添加车辆",
		    width: 400,
		    height: 350,
		    closed: true,
		    buttons:[{
				text:"添加",
				handler:function(){
					var data ="carno="+$("#carno").val()+
	  				"&cartype="+$("#cartype").val()+
	  				"&carid="+$("#carid").val();
					$.get("car/add.do",data,function(data){
								alert(data);
								$("#dlg").dialog("close");
								$("#dg").datagrid("reload");
							},"text");  	
				}
			},{
				text:"取消",
				handler:function(){
					$("#dlg").dialog("close");
				}
			}]
		});
		$("#dlg1").dialog({
		    title: "修改车辆",
		    width: 400,
		    height: 350,
		    closed: true,
		    buttons:[{
				text:"修改",
				handler:function(){
					var data ="id="+$("#iidd1").val()+
					"&carno="+$("#carno1").val()+
	  				"&cartype="+$("#cartype1").val()+
	  				"&carid="+$("#carid1").val();
					$.get("car/update.do",data,function(data){
								alert(data);
								$("#dlg1").dialog("close");
								$("#dg").datagrid("reload");
							},"text");  	
				}
			},{
				text:"取消",
				handler:function(){
					$("#dlg").dialog("close");
				}
			}]
		});
		$("#list").datagrid({	  		
  			url:"carmanage/findByCreateid.do?createid="+$("#applyid").val(),
  			striped:true,	  			
  			rownumbers:true,
  			columns:[[{
  				title:"车牌编号",
  				field:"carid",
  				width:100,
  				align:"center",
  			},{
  				title:"用车人",
  				field:"users",
  				width:100,
  				align:"center"
  			},{
  				title:"开始时间",
  				field:"begindate",
  				width:120,
  				align:"center",
  				formatter:date
  			},{
  				title:"结束时间",
  				field:"enddate",
  				width:120,
  				align:"center",
  				formatter:date
  			},{
  				title:"目的地",
  				field:"destination",
  				width:100,
  				align:"center"
  			},{
  				title:"申请时间",
  				field:"ordertime",
  				width:120,
  				align:"center",
  				formatter:date
  			},{
  				title:"状态",
  				field:"status",
  				width:83,
  				align:"center",
  				formatter:function (value){
					if(value==1){
						return "待审核";
					}else if(value==2){
						return "审核中";
					}else if(value==3){
						return "待审核";
					}else if(value==4){
						return "审核通过";
					}else if(value==4){
						return "已拒绝";
					}else if(value==5){
						return "已打回";
					}
				}
  			}]]
  		});
		
		$("#all").datagrid({	  		
  			url:"carmanage/findAll.do",
  			striped:true,	  			
  			rownumbers:true,
  			singleSelect:true,
  			columns:[[{
  				checkbox:true
  			},{
  				title:"车牌编号",
  				field:"carid",
  				width:77,
  				align:"right",
  			},{
  				title:"用车人",
  				field:"users",
  				width:77,
  				align:"right"
  			},{
  				title:"开始时间",
  				field:"begindate",
  				width:100,
  				align:"right",
  				formatter:date
  			},{
  				title:"结束时间",
  				field:"enddate",
  				width:100,
  				align:"right",
  				formatter:date
  			},{
  				title:"目的地",
  				field:"destination",
  				width:80,
  				align:"right"
  			},{
  				title:"申请时间",
  				field:"ordertime",
  				width:100,
  				align:"right",
  				formatter:date
  			},{
  				title:"申请人",
  				field:"createname",
  				width:100,
  				align:"right"
  			},{
  				title:"状态",
  				field:"status",
  				width:80,
  				align:"right",
  				formatter:function (value){
					if(value==1){
						return "待审核";
					}else if(value==2){
						return "审核中";
					}else if(value==3){
						return "待审核";
					}else if(value==4){
						return "审核通过";
					}else if(value==4){
						return "已拒绝";
					}else if(value==5){
						return "已打回";
					}
				}
  			}]]
  		});
		
		$("#qxyd").click(function(){
			var arr = $("#all").datagrid("getSelections");
			var id = arr[0].id;	
			$.get("carmanage/delete.do?id="+id,function(data){
				alert(data);
				$("#all").datagrid("reload");
				$("#list").datagrid("reload");
			},"text"); 
		});
		
		$("#search").click(function(){
			if(checkbegin()==false || checkend()==false){
				return false;		
			}
			$("#begindate1").val($("#begindate").val());
			$("#enddate1").val($("#enddate").val());
			$("#tacx").datagrid({	  		
	  			url:"carmanage/findByTime.do?begindate="+$("#begindate").val()+"&enddate="+$("#enddate").val(),
	  			striped:true,	  			
	  			rownumbers:true,
	  			singleSelect:true,
	  			columns:[[{
	  				checkbox:true
	  			},{
	  				title:"车牌号",
	  				field:"carno",
	  				width:200,
	  				align:"right",
	  			},{
	  				title:"车型",
	  				field:"cartype",
	  				width:255,
	  				align:"center"
	  			},{
	  				title:"编号",
	  				field:"carid",
	  				width:250,
	  				align:"center"
	  			}]],
	  			onSelect:function(index,rows){
	  				$.post("car/findById.do","id="+rows.id,function(data){
	  	  				$("#carId").val(data.carid);
	  	  			},"json");
	  				$.post("dept/findById.do","id="+$("#deptId").val(),function(data){
	  	  				$("#deptmanagerid").val(data.deptmanagerid);	  	  				  	  			
		  				$.post("users/findById.do","id="+$("#deptmanagerid").val(),function(data){
		  	  				$("#deptmanagername").val(data.name);	  	  				
		  	  			},"json");
	  				},"json");
	  			}
	  		});
		});
		
		 	
	});

	function add(){
	  	$("#dlg").dialog("open");
	}; 
	function update(value){
		$("#dlg1").dialog("open");	
		$.post("car/findById.do","id="+value,function(data){
  				$("#iidd1").val(value);
  				$("#carno1").val(data.carno);
  				$("#cartype1").val(data.cartype);
  				$("#carid1").val(data.carid);
  			},"json");
	};
	function date(value){
		return value.year+1900+"-"
		+(value.month+1)+"-"+value.date;
	};
	function del(value){
			$.messager.confirm("提示框", "你确定要删除吗?",function(r){
				if(r){
					var data = "id="+value;
					$.post(
		  				"car/delete.do",
		  				data,
		  				function(data){
		  				alert(data);
		  				$("#dg").datagrid("reload");
		  				},
		  				"text"
		  			);
				}
			});
		};
		function checkbegin(){
 			if($("#begindate").val()==""){
				alert("开始时间不能为空！");
				return false;
 			}
 		};
 		function checkend(){
 			if($("#enddate").val()==""){
				alert("结束时间不能为空！");
				return false;
 			}
 		};
     
     </script>
 <c:if test="${message!=null }">
	<script>
		alert('${message}');
	</script>
 </c:if>
     </head>
  
  <body>
  <div id="carbody">
  	<p><img src="css/chenwenjing/img/icons/contacts.png" width="32px" height="32px"/>&nbsp;&nbsp;<span>行政管理</span></p>
  	<div class="title">用车管理</div> 	
  	<div class="easyui-tabs">
  		<div title="用车预定" style="padding:10px" >
  		
  		<table id="list"></table>
  		<div class="content">
  		<table class="biaoge" cellpadding="0" cellspacing="0">
	  		<tr>
	  			<td>选择时间段：<input id="begindate"  type="text"/> to <input id="enddate"  type="text"/>&nbsp;&nbsp;&nbsp;&nbsp;
   					<input type="button" value="查询" id="search" class="button"></td>
	  		</tr>
  		</table>
   		<table id="tacx"></table>
   		<form method="post" action="carmanage/add.do" >
	    	<table cellpadding="0" cellspacing="0" class="biaoge">
	    		<tr>
	    			<td>车辆编号：
	    			<input id="begindate1" name="begindate"  type="hidden"/>
	    			<input id="enddate1" name="enddate"  type="hidden"/>
	    			</td>
	    			<td>
	    				<input type="hidden" name="id" value=""/>
						<input class="input-text" type="text" id="carId" name="carId" value="" readonly="readonly"/>
	    			</td>	
	    		</tr>
	    		<tr>
	    			<td>用车人：</td>
	    			<td>
						<input class="input-text" type="text" id="users" name="users" value="" />
	    			</td>	
	    		</tr>
	    		<tr>
	    			<td>司机：</td>
	    			<td>
						<input class="input-text" type="text" id="driver" name="driver" value="" />
	    			</td>	
	    		</tr>
	    		<tr>
	    			<td>随行人员：</td>
	    			<td>
						<input class="input-text" type="text" id="follow" name="follow" value="" />
	    			</td>	
	    		</tr>
	    		<tr>
	    			<td>用车部门：</td>
	    			<td>
						<input class="input-text" type="text" id="deptname" name=deptname value="${user.deptname}" readonly="readonly"/>
						<input class="input-text" type="hidden" id="deptid" name=deptid value="${user.deptid}" />
	    			</td>	
	    		</tr>
	    		<tr>
	    			<td>目的地：</td>
	    			<td>
						<input class="input-text" type="text" id="destination" name="destination" value="" />
	    			</td>	
	    		</tr>
	    		<tr>
	    			<td>申请里程(公里)：</td>
	    			<td>
						<input class="input-text" type="text" id="mileage" name="mileage" value="" />
	    			</td>	
	    		</tr>
	    		<tr>
	    			<td>用车事由：</td>
	    			<td>
	    				<textarea rows="3" cols="50" class="input-text" id="reason" name="reason"></textarea>
	    			</td>	
	    		</tr>
	    		<tr>
	    			<td>申请人：</td>
	    			<td><input class="input-text" type="text" id="applyname" name="applyname" value="${user.name}" readonly="readonly">
	    			<input class="input-text" type="hidden" id="applyid" name="applyid" value="${user.id}"></input>
						
	    			</td>	
	    		</tr>
	    		<tr>
	    			<td>下一步审批人：</td>
	    			<td><input class="input-text" type="hidden" id="deptId" name="deptId" value="${user.deptid}" />
						<input class="input-text" type="hidden" id="deptmanagerid" name="deptmanagerid" value=""/>
						<input class="input-text" type="text" id="deptmanagername" name="deptmanagername" value="" readonly="readonly"/>
	    			</td>	
	    		</tr>
    		</table>
    		<input class="button" type="submit" id="submit" name="submit" value="确定" />
    		<input class="button" type="reset" id="reset" name="reset" value="取消" />
    	</form>
      </div>
      </div>
      <c:if test="${user.deptid==1 || user.roleid==5 }">
      <div title="用车预定管理" style="padding:10px" >
      	<table id="all"></table>
      	<input type="button" value = "取消预定" id="qxyd" class="button">
      </div>
      
      <div title="车辆信息管理" style="padding:10px">
      	
      	<table id="dg" ></table>
      	<table id="dlg">
      		<tr>
      			<td>车牌号</td>
      			<td>
      			<input type="text" name="car.carno" id="carno"></td>
      		</tr>
      		<tr>
      			<td>车型</td>
      			<td><input type="text" name="car.cartype" id="cartype"></td>
      		</tr>
      		<tr>
      			<td>编号</td>
      			<td><input type="text" name="car.carid" id="carid"></td>
      		</tr>
      	</table>
      	<table id="dlg1">
      		<tr>
      			<td>车牌号</td>
      			<td><input type="hidden" name="car.id" id="iidd1">
      			<input type="text" name="car.carno" id="carno1"></td>
      		</tr>
      		<tr>
      			<td>车型</td>
      			<td><input type="text" name="car.cartype" id="cartype1"></td>
      		</tr>
      		<tr>
      			<td>编号</td>
      			<td><input type="text" name="car.carid" id="carid1"></td>
      		</tr>
      	</table>
      	</div>
      	</c:if>
      </div>
  	</div>	    
  </body>
</html>
